import java.io.PrintStream;


public class Jordanph implements Player, Piece {
	Board board;
	int player;
	int opponent;
	int numMovesPlayed;
	
	public int init(int n, int p) {
		board = new Board(n);
		player = p;
		if (player == BLACK)
			opponent = WHITE;
		else 
			opponent = BLACK;
		
		if (board == null)
			return INVALID;
		
		numMovesPlayed = 0;
					
		return 0;	
	}
	
	public int opponentMove(Move m) {
		if (!board.insertMove(m)) 
			return INVALID;
		
		numMovesPlayed++;
		return 0;
	}
	
	public Move makeMove() {
		Move bestMove;
		MinMax minmax = new MinMax(board, numMovesPlayed, player, opponent);
		numMovesPlayed++;
		
		bestMove = minmax.bestMove();
		return bestMove;
	}
	
	public void printBoard(PrintStream output){
		
		for(int row=0; row<board.size; row++){
			for(int col=0; col<board.size; col++) {
				output.print(board.board[row][col]);
			}
			output.println();
		}
	}
	
	public int getWinner() {
		if (board.numEmpty() != 0)
			return 0;
		
		int whitePieces = board.numPlayerPieces(WHITE);
		int blackPieces = board.numPlayerPieces(BLACK);

		if (whitePieces > blackPieces)
			return WHITE;
		else if (whitePieces < blackPieces){
			return BLACK;
		} else {
			return DEAD;
		}
				
	}
}
